//*Set Working Directory if needed*//
//* Should not need to be done if you are running the files   *//
//* per the instructions in the readme file  *//
/* cd Z:\Econ428_Sp15\Metelski\Documentation\Data\ */

//*Statistical Analysis*//

//Import Final Dataset*//
use Final\finaldataclean.dta, clear  

//*Set Panel/Time Variable*//
xtset area_fips time

//*Drop Non-Coal Counties*//
drop if coalemploymentmo3 == 0

//*********************Coal Direct Effects*************************//
xtreg d.lncoalemployment boom bust post Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe   
est sto Coal_Employment 

xtreg d.lncoalweeklywage boom bust post Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe 
est sto Coal_Average_Weekly_Wage 

xtreg d.lncoaltotalwage boom bust post Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe 
est sto Coal_Total_Wages 

//*Table 2*//
esttab  Coal_Employment Coal_Average_Weekly_Wage Coal_Total_Wages using Tables\Table2.rtf, title("Table 2") se r2 mtitles("Employment" "Average Weekly Wage" "Total Wages") star(* 0.10 ** 0.05 *** 0.01)

 
//********************Testing for Spillover*************************//
//Import Final Dataset*//
//*  Need to do this again because we want the non-coal counties now  */
use Final\finaldataclean.dta, clear  

//*Set Panel/Time Variable*//
xtset area_fips time

//*All Industry Spillover Effects*//
xtreg d.lnallindustriesemployment boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100  , fe
est sto All_Employment 

xtreg d.lnallindustriesweeklywage boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto All_Weekly_Wage 

xtreg d.lnallindustriestotalwage boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto All_Total_Wages 

//*All Industry without Coal Spillover Effects*//
xtreg d.lnallindustrymcoalemployment boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100  , fe
est sto All_No_Coal_Employment 

xtreg d.lnallindustrymcoaltotalwage boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto All_No_Coal_Total_Wages 

//*Table 3*//
esttab  All_Employment All_Weekly_Wage All_Total_Wages All_No_Coal_Employment All_No_Coal_Total_Wages using Tables\Table3.rtf, title("Table 3") se r2 mtitles("Employment" "Average Weekly Wage" "Total Wages" "Employment With No Coal" "Total Wages With No Coal") star(* 0.10 ** 0.05 *** 0.01)

 

//*Sector Spillover Effects*//

//*Employment*// 

xtreg d.lnconstructionemployment boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Construction 

xtreg d.lnretailemployment boom bust post treatmentboom treatmentbust treatmentpost   Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Retail_Trade 

xtreg d.lnserviceemployment boom bust post treatmentboom treatmentbust treatmentpost   Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Service 

xtreg d.lnmanufacturingemployment boom bust post treatmentboom treatmentbust treatmentpost  Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Manufacturing 

//*Table 4*//
esttab  Construction Retail_Trade Service Manufacturing using Tables\Table4.rtf, title("Table 4") se r2 mtitles("Construction" "Retail Trade" "Service" "Manufacturing") star(* 0.10 ** 0.05 *** 0.01)

 

//*Wage*// 

xtreg d.lnconstructionweeklywage boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Construction 

xtreg d.lnretailweeklywage  boom bust post treatmentboom treatmentbust treatmentpost   Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Retail_Trade 

xtreg d.lnserviceweeklywage  boom bust post treatmentboom treatmentbust treatmentpost   Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Service 

xtreg d.lnmanufacturingweeklywage boom bust post  treatmentboom treatmentbust treatmentpost  Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Manufacturing 

//*Table 5*//
esttab  Construction Retail_Trade Service Manufacturing using Tables\Table5.rtf, title("Table 5") se r2 mtitles("Construction" "Retail Trade" "Service" "Manufacturing") star(* 0.10 ** 0.05 *** 0.01)

 

//*Total Wage*// 

xtreg d.lnconstructiontotalwages boom bust post treatmentboom treatmentbust treatmentpost Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Construction 

xtreg d.lnretailtotalwages boom bust post treatmentboom treatmentbust treatmentpost   Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Retail_Trade 

xtreg d.lnservicetotalwages boom bust post treatmentboom treatmentbust treatmentpost   Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Service 

xtreg d.lnmanufacturingtotalwages boom bust post treatmentboom treatmentbust treatmentpost  Q2 Q3 Q4 malepop100 femalepop100 unemployed100, fe
est sto Manufacturing 

//*Table 6*//
esttab  Construction Retail_Trade Service Manufacturing using Tables\Table6.rtf, title("Table 6") se r2 mtitles("Construction" "Retail Trade" "Service" "Manufacturing") star(* 0.10 ** 0.05 *** 0.01)
 


//*Graphs in The Paper*// 
use Final\finaldatacleanappendix.dta, clear 

//*Figure 3*//
graph twoway line coalemploymentmo3 time if (area_fips == 21000), sort(time) title(KY Coal Employment: 2006-2011) note("*Data taken from third month of each quarter")   

//*Figure 4*//
graph twoway line coalemploymentmo3 time if (area_fips == 54000), sort(time) title(WV Coal Employment: 2006-2011) note("*Data taken from third month of each quarter")


//*Figure 7*//
graph twoway line coalavgwklywage time if (area_fips == 21000), sort(time) title(KY Coal Average Weekly Wage: 2006-2011) note("*Data taken from third month of each quarter")   

//*Figure 8*//
graph twoway line coalavgwklywage time if (area_fips == 54000), sort(time) title(WV Coal Average Weekly Wage: 2006-2011) note("*Data taken from third month of each quarter")

clear 

